import request from './index'

interface ApiResponse<T = unknown>{
    code: number,   // 状态码，200 表示成功
    message: string, // 登录成功后返回的消息
    data: T, // 登录成功后返回的数据
}


interface LoginParams {
    "username": string,
    "password": string, 
    "captcha_id": string,
    "captcha_code": string,
}



export const loginApi = (data: LoginParams) => {
    return request.post('/auth/login', data) as Promise<ApiResponse<Record<string, string | number>>>
}


export const getCaptchaApi = () => {
    return request.get('/auth/captcha') as Promise<ApiResponse<{
        image: string,
        id: string,
        expires_in: number,
        text: string,
    }>>
}


